<script setup>
  import api from "./api.js";
  import ApplyApproveBody from "./body.vue";

  const emit = defineEmits(['sub']);
  const openFlag = ref(false);

  const body = ref();
  const detailInfo = ref({});
  const todoData = ref({});
  provide('detailInfo', detailInfo);
  provide('todoData', todoData);

  function open(row) {
    todoData.value = row;
    openFlag.value = true;
    const applyId = row.applyId;

    api.detail(applyId).then(response=> {
      detailInfo.value = response;
    })
  }

  function close() {
    openFlag.value = false;
  }

  function reject() {

    api.reject({
      taskId: todoData.taskId,
      remark: todoData.remark
    }).then(()=> {
      emit('sub');
      close()
    })
  }

  function approve() {
    debugger
    const todoValue = todoData.value;
    api.approve(todoValue).then(()=> {
      emit('sub');
      close()
    })
  }

  defineExpose({
    open
  })

</script>

<template>
  <div>
    <!-- 添加或修改资产清单表对话框 -->
    <el-dialog ref="editDialog" v-model="openFlag" title="待办" width="50%" append-to-body>
      <ApplyApproveBody ref="body"></ApplyApproveBody>

      <div slot="footer" class="dialog-footer">
        <el-row type="flex" justify="end">
          <el-button type="danger" @click="reject">驳回</el-button>
          <el-button type="primary" @click="approve">同意</el-button>
        </el-row>
      </div>

    </el-dialog>
  </div>
</template>

<style scoped lang="scss">

</style>